package com.ruoyi.xsc.domain;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.core.annotation.Excel;
import com.ruoyi.common.core.web.domain.BaseEntity;

import javax.validation.constraints.AssertTrue;

/**
 * 订单表对象 orders
 * 
 * @author ruoyi
 * @date 2025-05-10
 */
public class Orders extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 主键id */
    @Excel(name = "主键id")
    private Long id;

    /** 商户id */
    @Excel(name = "商户id")
    private Long merchantId;

    /** 服务id */
    @Excel(name = "服务id")
    private Long serviceId;

    @Excel(name="车辆详情id")
    private Long carId;
    /** 订单编号 */
    @Excel(name = "订单编号")
    private String orderNum;

    /** 用户id */
    @Excel(name = "用户id")
    private Long userId;

    /** 订单价格 */
    @Excel(name = "订单价格")
    private BigDecimal orderPrice;

    /** 订单状态（0待支付，1待使用，2待评价 ,3 已取消,4已退款,5 已完成*/
    @Excel(name = "订单状态", readConverterExp = "0=待核销，1已完成，2已过期,0待支付，1待使用，2待评价 ,3 已取消,4已退款,5 已完成")
    private Long orderStatus;

    /** 预约时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "预约时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date reservationTime;

    /** 下单时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "下单时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date orderTime;

    /** 核销码【UUID产生、唯一】 */
    @Excel(name = "核销码【UUID产生、唯一】")
    private String verificationCode;

    /** 核销码图片 */
    @Excel(name = "核销码图片")
    private String verificationImg;

    /** 优惠卷id【每次只用使用一张】 */
    @Excel(name = "优惠卷id【每次只用使用一张】")
    private Long couponId;

    /** 删除状态(默认0，删除1) */
    @Excel(name = "删除状态(默认0，删除1)")
    private Long del;

    public void setId(Long id) 
    {
        this.id = id;
    }

    public Long getId() 
    {
        return id;
    }

    public void setMerchantId(Long merchantId) 
    {
        this.merchantId = merchantId;
    }

    public Long getMerchantId() 
    {
        return merchantId;
    }

    public void setServiceId(Long serviceId) 
    {
        this.serviceId = serviceId;
    }

    public Long getServiceId() 
    {
        return serviceId;
    }

    public void setOrderNum(String orderNum) 
    {
        this.orderNum = orderNum;
    }

    public String getOrderNum() 
    {
        return orderNum;
    }

    public Long getCarId() {
        return carId;
    }

    public void setCarId(Long carId) {
        this.carId = carId;
    }

    public void setUserId(Long userId)
    {
        this.userId = userId;
    }

    public Long getUserId() 
    {
        return userId;
    }

    public void setOrderPrice(BigDecimal orderPrice) 
    {
        this.orderPrice = orderPrice;
    }

    public BigDecimal getOrderPrice() 
    {
        return orderPrice;
    }

    public void setOrderStatus(Long orderStatus) 
    {
        this.orderStatus = orderStatus;
    }

    public Long getOrderStatus() 
    {
        return orderStatus;
    }

    public void setReservationTime(Date reservationTime) 
    {
        this.reservationTime = reservationTime;
    }

    public Date getReservationTime() 
    {
        return reservationTime;
    }

    public void setOrderTime(Date orderTime) 
    {
        this.orderTime = orderTime;
    }

    public Date getOrderTime() 
    {
        return orderTime;
    }

    public void setVerificationCode(String verificationCode) 
    {
        this.verificationCode = verificationCode;
    }

    public String getVerificationCode() 
    {
        return verificationCode;
    }

    public void setVerificationImg(String verificationImg) 
    {
        this.verificationImg = verificationImg;
    }

    public String getVerificationImg() 
    {
        return verificationImg;
    }

    public void setCouponId(Long couponId) 
    {
        this.couponId = couponId;
    }

    public Long getCouponId() 
    {
        return couponId;
    }

    public void setDel(Long del) 
    {
        this.del = del;
    }

    public Long getDel() 
    {
        return del;
    }
@AssertTrue(message = "下单时间必须早于预约时间")
    public boolean isValidOrderTime(){
        return orderTime==null || reservationTime==null || orderTime.before(reservationTime);
    }
    public void generateOrderNum(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String format = sdf.format(new Date());
        String randomPart=String.format("%04d", new Random().nextInt(9999));
        this.orderNum="ORD"+format+randomPart;
    }
    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
            .append("id", getId())
            .append("merchantId", getMerchantId())
            .append("serviceId", getServiceId())
            .append("orderNum", getOrderNum())
            .append("userId", getUserId())
                .append("carId",getCarId())
            .append("orderPrice", getOrderPrice())
            .append("orderStatus", getOrderStatus())
            .append("reservationTime", getReservationTime())
            .append("orderTime", getOrderTime())
            .append("verificationCode", getVerificationCode())
            .append("verificationImg", getVerificationImg())
            .append("couponId", getCouponId())
            .append("del", getDel())
            .toString();
    }
}
